package com.wavehi.producer;

import com.rabbitmq.client.Channel;
import com.wavehi.util.RabbitMQFactoryUtils;

import java.io.IOException;
import java.util.Scanner;

/**
 * @Description 生产者
 * @Author WaveHi
 * @Date 24/12/2021 下午 3:42
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */
public class Producer_01 {

    private final static String QUEUE_NAME = "Hello";

    public static void main(String[] args) throws Exception {

        //1.获取连接信道
        Channel channel = RabbitMQFactoryUtils.getChannel();
        //2.声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //3.准备消息
        Scanner scanner = new Scanner(System.in);
        String message = null;
        //4.发送消息
        while (scanner.hasNext()) {
            message = scanner.next();
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("Send message : " + message);
        }
    }
}
